package com.hc.sort.utils;

import java.io.FileInputStream;
import java.io.IOException;

import sun.audio.AudioPlayer;
import sun.audio.AudioStream;

public class SoundUtil {
	public static synchronized void playSound(String ss, String winF)
			throws IOException, InterruptedException {
		FileInputStream fileau;
		fileau = new FileInputStream("sound\\please.wav");
		AudioStream as = new AudioStream(fileau);
		AudioPlayer.player.start(as);
		Thread.sleep(500);

		for (int i = 0; i < ss.length(); i++) {
			fileau = new FileInputStream("sound\\" + ss.charAt(i) + ".wav");
			as = new AudioStream(fileau);
			AudioPlayer.player.start(as);
			Thread.sleep(500);
		}

		fileau = new FileInputStream("sound\\dao.wav");
		as = new AudioStream(fileau);
		AudioPlayer.player.start(as);
		Thread.sleep(500);

		for (int i = 0; i < winF.length(); i++) {
			fileau = new FileInputStream("sound\\" + winF.charAt(i) + ".wav");
			as = new AudioStream(fileau);
			AudioPlayer.player.start(as);
			Thread.sleep(500);
		}

		fileau = new FileInputStream("sound\\last.wav");
		as = new AudioStream(fileau);
		AudioPlayer.player.start(as);
		Thread.sleep(2000);
	}

	/**
		测试playSound()方法的作用
	*/
	public static void main(String[] args) {

		try {
			SoundUtil.playSound("A2015", "8");
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
